package com.sskj.qiangjin.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.qiangjin.bean.ShowPayBean;
import com.sskj.qiangjin.http.HttpConfig;
import com.sskj.qiangjin.ui.fragment.AddPayWayFragment;

/**
 * Created by Q-Kang on 2019/1/20.
 */

public class AddPayWayPresenter extends BasePresenter<AddPayWayFragment> {

    /**
     * 添加支付方式
     *
     * @param address
     * @param realname
     * @param bankcard
     * @param branch
     */
    public void addPayWay(String address, String realname, String bankcard, String branch, String bank) {
        httpService.addPayWay(address, realname, bankcard, branch, bank)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.getActivity().finish();
                        }
                    }
                });
    }

    public void showPay() {
        httpService.showPay()
                .execute(new JsonCallBack<HttpData<ShowPayBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<ShowPayBean>> response) {
                        HttpData httpData = response.body();
//                        ToastUtil.showShort(httpData.msg);
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.showPayWay((ShowPayBean) httpData.getData());
                        }
                    }
                });
    }
}
